package com.maimao.spider.task;

import com.maimao.spider.pipeline.BrandPipeline;
import com.maimao.spider.processor.BrandProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Spider;

import java.util.ArrayList;
import java.util.List;

/**
 * @author MaoLin Wang
 * @date 2019/11/2421:19
 */
@Component
public class BrandTask {

    public static final String PHONE_URL ="https://list.jd.com/list.html?cat=9987,653,655";
    public static final String COMPUTER_URL ="https://list.jd.com/list.html?cat=670,671,672";
    public static final String XIFASHUI ="https://list.jd.com/list.html?cat=16750,16751,16756";
    public static final String ZHENZHISHAN ="https://list.jd.com/list.html?cat=1315,1343,1356";
    public static final String XIDINGDENG ="https://list.jd.com/list.html?cat=9855,9856,9904";
    @Autowired
    private BrandProcessor brandProcessor;
    @Autowired
    private BrandPipeline brandPipeline;
    public static final List<String> all=new ArrayList<String>(18){{
        for (int i = 0; i < 18; i++) {
            add(PHONE_URL +"?a="+i);
        }
    }};

    //    @Scheduled(cron = "0 52 23 * * ?")
//    @Async("scheduleAsyncExecutor")
    public void spiderBrand(){
        System.out.println("爬取品牌");
        Spider spider=Spider.create(brandProcessor);
         spider.addUrl(XIDINGDENG)
                .addPipeline(brandPipeline)
                .start();
    }
}
